package com.hcandtx.Bms.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.hcandtx.Bms.bean.Product;
import com.hcandtx.Bms.bean.ShoppingTrolley;
import com.hcandtx.Bms.service.IProductService;
import com.hcandtx.Bms.service.IShoppingService;
import com.sun.xml.internal.ws.encoding.soap.SOAP12Constants;

@Controller("shoppingController")
@ResponseBody
public class ShoppingController {

	@Autowired
	private IShoppingService shoppingService;
	
	@Autowired
	private IProductService prodcutService;
	/*
	 * public String add(ShoppingTrolley shoppingTrolley) {
	 * 
	 * shoppingService.add(shoppingTrolley);
	 * shoppingService.deleteById(shoppingTrolley.getId()); return null;
	 * 
	 * } public List<ShoppingTrolley> findAll() {
	 * 
	 * List<ShoppingTrolley> shoppingTrolleys= shoppingService.findAll();
	 * System.out.println(shoppingTrolleys); return shoppingTrolleys;
	 * 
	 * }
	 */
	
	
	/* ǰ̨ */
	@RequestMapping("/shopping/getdata")
	public List<ShoppingTrolley> findUserShopping(int UserId) {
		System.out.println(UserId);
		List<ShoppingTrolley> shoppingTrolleys= shoppingService.findById(UserId);
		System.out.println(shoppingTrolleys);
		return shoppingTrolleys;
		
	}
	
	@RequestMapping("/shopping/addShopping")
	public  int addShopping( ShoppingTrolley shoppingTrolley) {
		System.out.println(shoppingTrolley);
		shoppingTrolley.setQuantity(1);
		int n= shoppingService.add(shoppingTrolley);
		
		System.out.println(n);
		return n;
		
	}
	
	@RequestMapping("/shopping/updateShopingQuantity")
	public int updateQuantity(int id,int quantity) {
		System.out.println(id);
		System.out.println(quantity);
		int n= shoppingService.updateQuantity(id,quantity);
		return n;
		
	}
	
	@RequestMapping("/shopping/deleteShopping")
	public int deleteShoping(int id) {
		int n= shoppingService.deleteById(id);
		return n;
		
	}
	
	
	
	
	
	
}
